home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / s_to_z / tpack / logindlg.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  2.9 KB  |  109 lines

  1. unit LoginDlg;
  2.  
  3. interface
  4.  
  5. uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, StdCtrls,
  6.   Buttons, dbiTypes
  7. , UserInfo;
  8.  
  9. {------------------------------------------------------------------------------}
  10. {                                                                              }
  11. {------------------------------------------------------------------------------}
  12.  
  13. type
  14.   TLoginDialogForm = class(TForm)
  15.     Label1: TLabel;
  16.     Password: TEdit;
  17.     OKBtn: TBitBtn;
  18.     CancelBtn: TBitBtn;
  19.     Label2: TLabel;
  20.   private
  21.     { Private declarations }
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. {------------------------------------------------------------------------------}
  27. {                                                                              }
  28. {------------------------------------------------------------------------------}
  29.  
  30.   TLoginDialog = class(TDialogShell)
  31.   private
  32.     fPassword: string;
  33.         {type plain/network/windows; include screen save pw coder and tests against bindery}
  34.     fRetries: Integer;
  35.     fRequired: Boolean;
  36.     fPasswordOk: Boolean;
  37.     fCaseSensitive: Boolean;
  38.   protected
  39.   public
  40.     constructor Create(aOwner:Tcomponent); Override;
  41.     procedure Execute; Override;
  42.     function Login(MasterPassword:String):Boolean;
  43.   published
  44.     property CaseSensitive: Boolean read fCaseSensitive write fCaseSensitive;
  45.     property PassWord: String read fPassWord write fPassword;
  46.     property PassWordOk: Boolean read fPassWordOk write fPasswordOk stored false;
  47.     property Required: Boolean read fRequired write fRequired default true;
  48.     property Retries: Integer read fRetries write fRetries default 2;
  49.     end;
  50.  
  51. {------------------------------------------------------------------------------}
  52. {                                                                              }
  53. {------------------------------------------------------------------------------}
  54.  
  55. implementation
  56.  
  57. uses SysUtils;
  58.  
  59. {$R *.DFM}
  60.  
  61.  
  62. constructor TLoginDialog.Create(aOwner:TComponent);
  63. begin
  64.   inherited Create(aOwner);
  65.   fRequired:=True;
  66.   fRetries:=2;
  67. end;
  68.  
  69. procedure TLoginDialog.Execute;
  70. var
  71.   Cursor:TCursor;
  72.   i: integer;
  73. begin
  74.   if (not fRequired) or (fPassword='') then begin
  75.     fPasswordOk:=True;
  76.     exit;
  77.     end;
  78.   fPasswordOk:=False;
  79.   Cursor:=Screen.Cursor;
  80.   Screen.Cursor:=crDefault;
  81.   With TLoginDialogForm.Create(Application) do try
  82.     for i:=0 to fRetries do begin
  83.       Password.SelectAll;
  84.       if ShowModal<>IdOk then
  85.         break;
  86.       if fCaseSensitive then
  87.         fPasswordOk:= (Password.Text=fPassword)
  88.       else
  89.         fPasswordOk:= (uppercase(Password.Text)=uppercase(fPassword));
  90.       if fPasswordOk then
  91.         break;
  92.       end;
  93.   finally
  94.     Free;
  95.     end;
  96.   Screen.Cursor:=Cursor;
  97. end;
  98.  
  99. function TLoginDialog.Login(MasterPassword:String):boolean;
  100. begin
  101.   fPassWord:= MasterPassword;
  102.   Execute;
  103.   fPassword:='';
  104.   Result:= fPasswordOk;
  105. end;
  106.  
  107. end.
  108.  
  109.